package test;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

/**
 * Created by Caesar on 2016/1/28.
 */
public class LongestConsec {

    public static String longestConsec(String[] strarr, int k) {
        StringBuffer result = new StringBuffer();
        TreeSet<String> set = new TreeSet(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if (o1.length() < o2.length())
                    return 1;
                else if(o1.equals(o2))
                    return 0;
                else
                    return -1;
            }
        });
        for (int i = 0; i < strarr.length; i++)
            set.add(strarr[i]);
        Iterator<String> it = set.iterator();
        for (int i = 0; i < k; i++) {
            if (it.hasNext())
                result.append(it.next());
        }
        return result.toString();
    }

    public static void main(String[] args) {
        System.out.println(longestConsec(new String[] {"wlwsasphmxx","owiaxujylentrklctozmymu","wpgozvxxiu"}, 2));
    }
}
